package com.example.controller;


import com.example.interceptor.Auth;
import com.example.service.ClassService;
import com.example.util.DataMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.example.model.Class;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: tao95
 * Date: 2017/5/9
 * Time: 19:59
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Auth
@Controller
@RequestMapping("class")
@Api(value = "class",tags = "班级管理类")
public class ClassController {
    @Autowired
    private ClassService classServiceImpl;
    @RequestMapping(value = "/addClass",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.POST})
    @ApiOperation("添加班级接口")
    public String  addAdmin(
            @ApiParam(name = "Class",value = "班级",required = true) Class classes,
            HttpServletRequest request){
        ModelAndView model = new ModelAndView();
        DataMap dataMap = classServiceImpl.insertClass(classes);
        if((Integer)dataMap.get("code") == 10000){
            model.addObject("addClass","success");
        }else{
            model.addObject("addClass","Fail");
        }
        return "forward:/classList";
    }
    @RequestMapping(value = "/delClass",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.GET})
    @ApiOperation("删除班级接口")
    public String  delCourse(
            @ApiParam(name = "id",value = "班级id",required = true) Integer id,
            HttpServletRequest request){
        ModelAndView model = new ModelAndView();
        DataMap dataMap = classServiceImpl.delClass(id);
        if((Integer)dataMap.get("code") == 10000){
            model.addObject("delClass","success");
        }else{
            model.addObject("delClass","Fail");
        }
        return "forward:/courseList";
    }

}